package cn.ibizlab.util.adapter.service;

import net.ibizsys.central.dataentity.IDataEntityRuntime;
import net.ibizsys.central.util.ISearchContext;
import net.ibizsys.model.dataentity.action.IPSDEAction;
import net.ibizsys.model.dataentity.ds.IPSDEDataSet;
import org.springframework.data.domain.Page;
import net.ibizsys.model.dataentity.ds.IPSDEDataQuery;
import java.util.List;
import java.util.Map;

/**
 * runtime适配服务对象：用于驱动 runtime 执行实体逻辑、前/后附加逻辑及runtime回调标准实体行为、sql调用等处理
 */
public interface SysRuntimeAdapterService {

    /**
     * 执行实体行为
     * @param dataEntityRuntime
     * @param iPSDEAction
     * @param args
     * @param actionData
     * @return
     * @throws Throwable
     */
    Object executeAction(IDataEntityRuntime dataEntityRuntime, IPSDEAction iPSDEAction, Object[] args, Object actionData) throws Throwable ;

    /**
     * 执行标准实体行为
     *
     * @param dataEntityRuntime
     * @param iPSDEAction
     * @param arg
     * @return
     * @throws Throwable
     */
    Object executeActionReal(IDataEntityRuntime dataEntityRuntime, IPSDEAction iPSDEAction, Object arg) throws Throwable;

    /**
     * 执行标准sql调用
     *
     * @param strSQL
     * @param params
     * @return
     */
    int executeSQLReal(String strSQL, Map<String, Object> params) throws Throwable;

    /**
     * 执行标准数据查询
     *
     * @param dataEntityRuntime
     * @param dataSet
     * @param searchContext
     * @return
     * @throws Throwable
     */
    Page fetchDataSetReal(IDataEntityRuntime dataEntityRuntime, IPSDEDataSet dataSet, ISearchContext searchContext) throws Throwable;

    /**
     * 执行标准数据查询
     *
     * @param dataEntityRuntime
     * @param query
     * @param searchContext
     * @return
     * @throws Throwable
     */
    List fetchDataSetReal(IDataEntityRuntime dataEntityRuntime, IPSDEDataQuery query, ISearchContext searchContext) throws Throwable;

    /**
     * 执行标准检查主键
     *
     * @param dataEntityRuntime
     * @param key
     * @return
     */
    int checkKeyReal(IDataEntityRuntime dataEntityRuntime, Object key) throws Throwable;

    /**
     * 执行标准插入操作（批处理）
     * @param dataEntityRuntime
     * @param args
     * @return
     */
    Object executeInsert(IDataEntityRuntime dataEntityRuntime, List<Map<String, Object>> args) throws Throwable;

    /**
     * 执行标准更新操作（批处理）
     * @param dataEntityRuntime
     * @param args
     * @return
     */
    Object executeUpdate(IDataEntityRuntime dataEntityRuntime, List<Map<String, Object>> args) throws Throwable;

    /**
     * 执行标准插入操作（单数据）
     * @param dataEntityRuntime
     * @param arg
     * @return
     */
    Object executeInsert(IDataEntityRuntime dataEntityRuntime, Map<String,java.lang.Object> arg) throws Throwable;

    /**
     * 执行标准更新操作（单数据）
     * @param dataEntityRuntime
     * @param arg
     * @return
     */
    Object executeUpdate(IDataEntityRuntime dataEntityRuntime, Map<String,java.lang.Object> arg) throws Throwable;
}
